// pages/order_creted/index.js
var dateTimePicker = require('../../utils/dateTimePicker.js');
const App = getApp();

var animation
// 时间
const date = new Date()
const years = []
const months = []
const days = []

for (let i = 1990; i <= date.getFullYear(); i++) {
  years.push(i)
}

for (let i = 1; i <= 12; i++) {
  var k = i;
  if (0 <= i && i <= 9) {
    k = "0" + (i);
  } else {
    k = (i);
  }
  months.push(k)
}

for (let i = 1; i <= 31; i++) {
  var k = i;
  if (0 <= i && i <= 9) {
    k = "0" + (i);
  } else {
    k = (i);
  }
  days.push(k)
}
Page({
  /**
   * 组件的初始数据
   */
  data: {
    date: '2018-10-01',
    time: '12:00',
    dateTimeArray: null,
    dateTime: null,
    dateTimeArray1: null,
    dateTime1: null,
    startYear: 2000,
    endYear: 2100,
    index: 0,
    categoryList: [{
      id: '123',
      name: '111'
    }], //商户
    showCategory: '请选择医院',
    discount: '', //系统参数折扣
    list: [{
      stepInfo: [{
          status: 0,
          pro_name: '填写订单'
        },
        {
          status: 1,
          pro_name: '在线支付'
        },
        {
          status: 2,
          pro_name: '陪诊'
        },
        {
          status: 3,
          pro_name: '服务完成'
        },
      ],
      sel_icon: "../../images/right.png",
      pro_color: '#3DB969'
    }, ],
    array: ['美国', '中国', '巴西', '日本'],
    index: 0,
    k_name: '请选择服务科室',
    currentIndex: 0,
    dateValue: '请选择服务时间',
    typeName: '代约检查',
    peopleList: ['是', '否'],
    report_type: '请选择服务类型',
    reportList: ['纸质报告', '电子报告'],
    mailList: ['否', '是'],
    relationshipName: '请选择',
    imageList: '',
    imageLists: '',
    register_image_url: '', //挂号凭证      int
    summary: '', //内容概述   text
    call_phone: '否', //现场打电话   varchar(2)是/否
    call_phoneName: '否',
    buy_medicine: '否', //买药及开检查：buy_medicine varchar(2)    是/否
    buy_medicineName: '否',
    other_needs: '', //其他需求：other_needs
    phone: '', //联系电话：phone 
    is_prove: '否', //开具出院证明：is_prove     varchar(2)是/否
    is_proveName: '否',
    Inpatient_no: '', //住院号：Inpatient_no      varchar(25)
    Invoice_and_ID_card: '', //发票及身份证在何处：Invoice_and_ID_card     varchar(255)
    discharge_time: '请选择出院时间', //出院时间：discharge_time      time
    is_prescription: '否', //是否处方药：is_prescription      varchar(2) 是/否
    is_prescriptionName: '否',
    report_barcode_url: '', //报告条形码report_barcode_url    int       
    is_mail: '0', //是否邮件：is_mail      int  :1是   0：为否
    is_mailName: '否',
    mail_address_id: '', //mail_address_id      int   
    receiving_method: '', //收件方式：receiving_method
    case_presentation: '', //病情介绍：case_presentation   text
    detail: {},
    service_time: '请选择服务时间', //服务时间
    patient_id: '', //就诊人
    registration_no: '', //登记号

    patient_name: '请选择就诊人',
    department_id: '',
    drugs: [{
      key_name: '',
      key_describe: '',
      key_image:[]
    }],
    address: '请选择邮寄地址',
    showImg: true,
    service_price: '',
    service_content: '',
    is_ask: '否',
    checkeds:false
  },

  /**
   * 组件的方法列表
   */
  datePickerBindchange: function (e) {
    this.setData({
      dateValue: e.detail.value,
      service_time: e.detail.value
    })
  },
  pickChange: function (e) {
    this.setData({
      index: e.detail.value
    });
  },

  bindPickerChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index: e.detail.value
    })
  },
  bindDepart: function (e) {
    console.log(e)
    wx.navigateTo({
      url: '/pages/department/index?department_id=' + this.data.department_id + '&type=' + 1,
    })
  },
  bindPatient: function (e) {
    wx.navigateTo({
      url: '/pages/patient/index?type=' + 1 + '&name=' + this.data.k_name + '&goods_id=' + this.data.goods_id + '&patient_id=' + this.data.patient_id + '&patient_name=' + this.data.patient_name + '&department_id=' + wx.getStorageSync('department_id_n') + '&mail_address_id=' + this.data.mail_address_id + '&address=' + this.data.address,
    })
  },

  onToType() {
    console.log(this.data.goods_id)
    if (this.data.goods_id == undefined) {
      wx.showToast({
        title: '请先选择医院',
        icon: 'none'
      })
    } else {
      wx.navigateTo({
        url: '/pages/s_type/index?id=' + this.data.goods_id,
      })
    }

  },
  onShow() {
    let {
      list
    } = this.data;
    list.forEach(item => {
      let onePer = item.stepInfo.filter(i0 => i0.status == 1).length;
      item.per = 100 / (item.stepInfo.length - 1) * (onePer - 1)
    })

    this.setData({
      list,
      checkeds:false
    })
    if (this.data.type_num != '1') {
      this.setData({
        shop_id: wx.getStorageSync('shop_id'),
        showCategory: wx.getStorageSync('showCategory') ? wx.getStorageSync('showCategory') : '请选择',
        department_id: wx.getStorageSync('department_id'),
        service_price: wx.getStorageSync('service_price'),
        goods_id: wx.getStorageSync('goods_id_a')
      })
    }

  },
  onToAgreement() {
    wx.navigateTo({
      url: '/pages/agreement/index',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options)
    var obj = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear);
    var obj1 = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear);
    // 精确到分的处理，将数组的秒去掉
    var lastArray = obj1.dateTimeArray.pop();
    var lastTime = obj1.dateTime.pop();
    var duag= [{
      key_name: '',
      key_describe: '',
      key_image:[]
    }]
    this.setData({
      dateTime: obj.dateTime,
      dateTimeArray: obj.dateTimeArray,
      dateTimeArray1: obj1.dateTimeArray,
      dateTime1: obj1.dateTime,
      call_phoneName:wx.getStorageSync('call_phoneName')?wx.getStorageSync('call_phoneName'):'否',
      call_phone:wx.getStorageSync('call_phoneName')?wx.getStorageSync('call_phoneName'):'否',
      buy_medicineName:wx.getStorageSync('buy_medicineName')?wx.getStorageSync('buy_medicineName'):'否',
      buy_medicine:wx.getStorageSync('buy_medicineName')?wx.getStorageSync('buy_medicineName'):'否',
      is_mailName:wx.getStorageSync('is_mailName')?wx.getStorageSync('is_mailName'):'否',
      is_mail:wx.getStorageSync('is_mailName')?wx.getStorageSync('is_mailName'):'否',
      is_ask:wx.getStorageSync('is_ask')?wx.getStorageSync('is_ask'):'否',
      report_type:wx.getStorageSync('report_type')?wx.getStorageSync('report_type'):'请选择服务类型',
      is_prescriptionName:wx.getStorageSync('is_prescriptionName')?wx.getStorageSync('is_prescriptionName'):'否',
      is_prescription:wx.getStorageSync('is_prescriptionName')?wx.getStorageSync('is_prescriptionName'):'否',
      service_time:wx.getStorageSync('service_time')?wx.getStorageSync('service_time'):'请选择服务时间',
      discharge_time:wx.getStorageSync('discharge_time')?wx.getStorageSync('discharge_time'):'请选择出院时间',
      register_image_url:wx.getStorageSync('register_image_url')?wx.getStorageSync('register_image_url'):'',
      report_barcode_url:wx.getStorageSync('report_barcode_url')?wx.getStorageSync('report_barcode_url'):'',
      drugs:wx.getStorageSync('drugs')?wx.getStorageSync('drugs'):duag,
      receiving_method:wx.getStorageSync('receiving_method')?wx.getStorageSync('receiving_method'):'',
      case_presentation:wx.getStorageSync('case_presentation')?wx.getStorageSync('case_presentation'):'',
      phone:wx.getStorageSync('phone')?wx.getStorageSync('phone'):'',
      service_content:wx.getStorageSync('service_content')?wx.getStorageSync('service_content'):'',
      other_needs:wx.getStorageSync('other_needs')?wx.getStorageSync('other_needs'):'',
      Inpatient_no:wx.getStorageSync('Inpatient_no')?wx.getStorageSync('Inpatient_no'):'',
      registration_no:wx.getStorageSync('registration_no')?wx.getStorageSync('registration_no'):'',
      Invoice_and_ID_card:wx.getStorageSync('Invoice_and_ID_card')?wx.getStorageSync('Invoice_and_ID_card'):'',
      summary:wx.getStorageSync('summary')?wx.getStorageSync('summary'):'',
      department_id:options.department_id
    });
    let _this = this;

    var typeNun = options.typeName
    if (typeNun == '1') {
      _this.setData({
        category_id: options.category_id ? options.category_id : wx.getStorageSync('category_id'),
        category_name: options.Typename ? options.Typename : wx.getStorageSync('category_name'),
        type_num: options.typeName
      })
      if (options.category_id) {
        wx.setStorageSync('category_id', options.category_id)
      }
      if (options.Typename) {
        wx.setStorageSync('category_name', options.Typename)
      }
    } else {
      _this.setData({
        k_name: options.name,
        goods_id: options.goods_id,
        patient_id: options.patient_id? options.patient_id : wx.getStorageSync('patient_id'),
        patient_name: options.patient_name? options.patient_name : wx.getStorageSync('patient_name'),
        department_id_n: options.department_id,
        mail_address_id: options.mail_address_id,
        address: options.address,
        category_id: options.category_id ? options.category_id : wx.getStorageSync('category_id'),
        category_name: options.Typename ? options.Typename : wx.getStorageSync('category_name'),
      });
      // if(options.goods_id){
      //   wx.setStorageSync('goods_id_a', options.goods_id)
      // }
      if(options.patient_id){
        wx.setStorageSync('patient_id', options.patient_id)
      }
      if(options.patient_name){
        wx.setStorageSync('patient_name', options.patient_name)
      }
      if(options.department_id){
        wx.setStorageSync('department_id_n', options.department_id)
      }
      // if(options.name){
      //   wx.setStorageSync('k_name_a', options.name)
      // }
      // if(options.mail_address_id){
      //   wx.setStorageSync('mail_address_id', options.mail_address_id)
      // }
      // if(options.address){
      //   wx.setStorageSync('address', options.address)
      // }
      if (options.category_id) {
        wx.setStorageSync('category_id', options.category_id)
      }
      if (options.Typename) {
        wx.setStorageSync('category_name', options.Typename)
      }
    }


    // _this.getData();
    _this.gethotel()
  },
  getData() {

    let app = this
    App._get('goods/detailInfo', {
      shop_id: app.data.shop_id,
      category_id: app.data.category_id
    }, result => {
      // 设置顶部导航栏栏
      // _this.setPageBar(result.data.page);
      console.log(result)
      app.setData({
        detail: result.data.detail,
        typeName: result.data.detail.category.name,
      });
    });
  },
  changeCheckeds(e){
    console.log(e)
    let val = e.detail.value
    if(val.length>0){
      this.setData({
        checkeds:true
      })
    }else{
      this.setData({
        checkeds:false
      })
    }
   
    console.log(this.data.checkeds)
  },
  downTo() {
    
    let app = this;
    let extend = {
      register_image_url: app.data.register_image_url, //挂号凭证      int
      summary: app.data.summary, //内容概述   text
      call_phone: app.data.call_phone, //现场打电话   varchar(2)是/否
      buy_medicine: app.data.buy_medicine, //买药及开检查：buy_medicine varchar(2)    是/否
      other_needs: app.data.other_needs, //其他需求：other_needs
      phone: app.data.phone, //联系电话：phone 
      is_prove: app.data.is_prove, //开具出院证明：is_prove     varchar(2)是/否
      Inpatient_no: app.data.Inpatient_no, //住院号：Inpatient_no      varchar(25)
      Invoice_and_ID_card: app.data.Invoice_and_ID_card, //发票及身份证在何处：Invoice_and_ID_card     varchar(255)
      discharge_time: app.data.discharge_time, //出院时间：discharge_time      time
      is_prescription: app.data.is_prescription, //是否处方药：is_prescription      varchar(2) 是/否
      report_barcode_url: app.data.report_barcode_url, //报告条形码report_barcode_url    int       
      is_mail: app.data.is_mail, //是否邮件：is_mail      int  :1是   0：为否
      mail_address_id: app.data.mail_address_id, //邮件地址：mail_address      int   
      receiving_method: app.data.receiving_method, //收件方式：receiving_method
      case_presentation: app.data.case_presentation, //病情介绍：case_presentation   text
      registration_no: app.data.registration_no, //登记号
      is_ask: app.data.is_ask,
      report_type: app.data.report_type
    }

    if(this.data.checkeds==true){
      console.log(this.data.goods_id)
      if(this.data.goods_id==''||this.data.goods_id==undefined){
        App.showError('请填写信息', () => {
        });
      }else{
        console.log(this.data.department_id_n)
        App._post_form('order/buynow', {
          shop_id: app.data.shop_id,
          extend: JSON.stringify(extend),
          service_time: app.data.service_time, //服务时间
          patient_id: app.data.patient_id, //就诊人
          department_id: wx.getStorageSync('department_id_n'),
          goods_id: app.data.goods_id,
          drugs: JSON.stringify(app.data.drugs),
          service_content: app.data.service_content,
          province_id:wx.getStorageSync('province_id'),
          city_id:wx.getStorageSync('city_id')
        }, result => {
          console.log(result)
    
          App.wxPayment({
            payment: result.data.payment,
            success: res => {
              wx.switchTab({
                url: '/pages/order_new/index',
              })
              wx.setStorageSync('call_phoneName','')
              wx.setStorageSync('buy_medicineName','')
              wx.setStorageSync('is_mailName','')
              wx.setStorageSync('is_ask','')
              wx.setStorageSync('report_type','')
              wx.setStorageSync('is_prescriptionName','')
              wx.setStorageSync('service_time','')
              wx.setStorageSync('discharge_time','')
              wx.setStorageSync('register_image_url', '')
              wx.setStorageSync('report_barcode_url', '')
              wx.setStorageSync('receiving_method', '')
              wx.setStorageSync('case_presentation', '')
              wx.setStorageSync('phone','')
              wx.setStorageSync('service_content', '')
              wx.setStorageSync('other_needs', '')
              wx.setStorageSync('Inpatient_no', '')
              wx.setStorageSync('registration_no', '')
              wx.setStorageSync('Invoice_and_ID_card', '')
              wx.setStorageSync('summary', '')
              wx.setStorageSync('patient_id','')
              wx.setStorageSync('patient_name','')
              var duag= [{
                key_name: '',
                key_describe: '',
                key_image:[]
              }]
              wx.setStorageSync('drugs', duag)
            },
            fail: res => {
              App.showError(result.msg.error, () => {
                wx.switchTab({
                  url: '/pages/order_new/index',
                })
                wx.setStorageSync('call_phoneName','')
                wx.setStorageSync('buy_medicineName','')
                wx.setStorageSync('is_mailName','')
                wx.setStorageSync('is_ask','')
                wx.setStorageSync('report_type','')
                wx.setStorageSync('is_prescriptionName','')
                wx.setStorageSync('service_time','')
                wx.setStorageSync('discharge_time','')
                wx.setStorageSync('register_image_url', '')
                wx.setStorageSync('report_barcode_url', '')
                wx.setStorageSync('receiving_method', '')
                wx.setStorageSync('case_presentation', '')
                wx.setStorageSync('phone','')
                wx.setStorageSync('service_content', '')
                wx.setStorageSync('other_needs', '')
                wx.setStorageSync('Inpatient_no', '')
                wx.setStorageSync('registration_no', '')
                wx.setStorageSync('Invoice_and_ID_card', '')
                wx.setStorageSync('summary', '')
                wx.setStorageSync('patient_id','')
                wx.setStorageSync('patient_name','')
                var duag= [{
                  key_name: '',
                  key_describe: '',
                  key_image:[]
                }]
                wx.setStorageSync('drugs', duag)
              });
            },
          });
        })
      }
    }else{
      App.showError('请阅读勾选用户协议后下单', () => {
        // wx.switchTab({
        //   url: '/pages/index/index',
        // })
      });
    }
    
  },

  gethotel() {
    let app = this
    App._get('goods/getShop', {
      category_id: this.data.category_id
    }, result => {
      // 设置顶部导航栏栏
      // _this.setPageBar(result.data.page);
      let detail = result.data.list
      detail.forEach(el => {
        const text = el.summary
        const chars = text.split(',');
        el.summarys = chars
      })
      app.setData({
        categoryList: detail
      });
    })
  },
  bindChangeCate: function (e) {
    let index = e.detail.value;
    let text = this.data.categoryList[index].shop_name;
    this.setData({
      cate_index: e.detail.value,
      showCategory: text,
      shop_id: this.data.categoryList[index].shop_id,
      department_id: this.data.categoryList[index].department_ids,
      service_price: this.data.categoryList[index].service_price,
      goods_id: this.data.categoryList[index].goods_id
    });

    wx.setStorageSync('shop_id', this.data.categoryList[index].shop_id)
    wx.setStorageSync('showCategory', text)
    wx.setStorageSync('department_id', this.data.categoryList[index].department_ids)
    wx.setStorageSync('goods_id_a', this.data.categoryList[index].goods_id)
    wx.setStorageSync('service_price', this.data.categoryList[index].service_price)
    //查询事件写在此处

    // this.getData()
  },
  changeDateTimeColumn1(e) {
    var arr = this.data.dateTime1,
      dateArr = this.data.dateTimeArray1;

    arr[e.detail.column] = e.detail.value;
    dateArr[2] = dateTimePicker.getMonthDay(dateArr[0][arr[0]], dateArr[1][arr[1]]);

    this.setData({
      dateTimeArray1: dateArr,
      dateTime1: arr
    });
    var y = this.data.dateTimeArray1[0][this.data.dateTime1[0]]
    var m = this.data.dateTimeArray1[1][this.data.dateTime1[1]]
    var d = this.data.dateTimeArray1[2][this.data.dateTime1[2]]
    var h = this.data.dateTimeArray1[3][this.data.dateTime1[3]]
    var s = this.data.dateTimeArray1[4][this.data.dateTime1[4]]
    this.setData({
      service_time: y + '-' + m + '-' + d + ' ' + h + ':' + s
    })
    wx.setStorageSync('service_time', this.data.service_time)
    console.log(this.data.service_time)
  },
  changeDateTimeColumn2(e) {
    var arr = this.data.dateTime1,
      dateArr = this.data.dateTimeArray1;

    arr[e.detail.column] = e.detail.value;
    dateArr[2] = dateTimePicker.getMonthDay(dateArr[0][arr[0]], dateArr[1][arr[1]]);

    this.setData({
      dateTimeArray1: dateArr,
      dateTime1: arr
    });
    var y = this.data.dateTimeArray1[0][this.data.dateTime1[0]]
    var m = this.data.dateTimeArray1[1][this.data.dateTime1[1]]
    var d = this.data.dateTimeArray1[2][this.data.dateTime1[2]]
    var h = this.data.dateTimeArray1[3][this.data.dateTime1[3]]
    var s = this.data.dateTimeArray1[4][this.data.dateTime1[4]]
    this.setData({
      discharge_time: y + '-' + m + '-' + d + ' ' + h + ':' + s
    })
    wx.setStorageSync('discharge_time', this.data.discharge_time)
    console.log(this.data.discharge_time)
  },


  // 是否需要问诊
  changeis_ask() {
    let app = this;
    wx.showActionSheet({
      itemList: app.data.peopleList,
      success: function (res) {
        console.log(res.tapIndex)
        let is_askName = ''
        if (res.tapIndex == 0) {
          is_askName = '是'
        } else if (res.tapIndex == 1) {
          is_askName = '否'
        }
        app.setData({
          is_ask: is_askName
        })
        wx.setStorageSync('is_ask', is_askName)
      },
      fail: function (res) {
        console.log(res.errMsg)
      }
    })
  },
  // 报告类型
  changReport_type() {
    let app = this;
    wx.showActionSheet({
      itemList: app.data.reportList,
      success: function (res) {
        console.log(res.tapIndex)
        let report_typeName = ''
        if (res.tapIndex == 0) {
          report_typeName = '纸质报告'
        } else if (res.tapIndex == 1) {
          report_typeName = '电子报告'
        }
        app.setData({
          report_type: report_typeName
        })
        wx.setStorageSync('report_type', report_typeName)
      },
      fail: function (res) {
        console.log(res.errMsg)
      }
    })
  },

  // 开具出院证明
  changeis_proveName() {
    let app = this;
    wx.showActionSheet({
      itemList: app.data.peopleList,
      success: function (res) {
        console.log(res.tapIndex)
        let is_proveName = ''
        if (res.tapIndex == 0) {
          is_proveName = '是'
        } else if (res.tapIndex == 1) {
          is_proveName = '否'
        }
        app.setData({
          is_prove: is_proveName,
          is_proveName: is_proveName
        })
      },
      fail: function (res) {
        console.log(res.errMsg)
      }
    })
  },
  // 现场打电话
  changeCall_phone() {
    let app = this;
    wx.showActionSheet({
      itemList: app.data.peopleList,
      success: function (res) {
        console.log(res.tapIndex)
        let call_phoneName = ''
        if (res.tapIndex == 0) {
          call_phoneName = '是'
        } else if (res.tapIndex == 1) {
          call_phoneName = '否'
        }
        app.setData({
          call_phone: call_phoneName,
          call_phoneName: call_phoneName
        })
        wx.setStorageSync('call_phoneName', call_phoneName)
      },
      fail: function (res) {
        console.log(res.errMsg)
      }
    })
  },

  // 买药剂开检查
  changebuy_medicineName() {
    let app = this;
    wx.showActionSheet({
      itemList: app.data.peopleList,
      success: function (res) {
        console.log(res.tapIndex)
        let buy_medicineName = ''
        if (res.tapIndex == 0) {
          buy_medicineName = '是'
        } else if (res.tapIndex == 1) {
          buy_medicineName = '否'
        }
        app.setData({
          buy_medicine: buy_medicineName,
          buy_medicineName: buy_medicineName
        })
        wx.setStorageSync('buy_medicineName', buy_medicineName)
      },
      fail: function (res) {
        console.log(res.errMsg)
      }
    })
  },
  // 是否处方药
  changeis_prescriptionName() {
    let app = this;
    wx.showActionSheet({
      itemList: app.data.peopleList,
      success: function (res) {
        console.log(res.tapIndex)
        let is_prescriptionName = ''
        if (res.tapIndex == 0) {
          is_prescriptionName = '是'
        } else if (res.tapIndex == 1) {
          is_prescriptionName = '否'
        }
        app.setData({
          is_prescription: is_prescriptionName,
          is_prescriptionName: is_prescriptionName
        })
        wx.setStorageSync('is_prescriptionName', is_prescriptionName)
      },
      fail: function (res) {
        console.log(res.errMsg)
      }
    })
  },

  // 是否邮寄
  changeis_mailName() {
    let app = this;
    wx.showActionSheet({
      itemList: app.data.mailList,
      success: function (res) {
        console.log(res.tapIndex)
        let is_mailName = ''
        if (res.tapIndex == 0) {
          is_mailName = '否'
        } else if (res.tapIndex == 1) {
          is_mailName = '是'
        }
        app.setData({
          is_mail: res.tapIndex,
          is_mailName: is_mailName
        })
        wx.setStorageSync('is_mailName', is_mailName)
      },
      fail: function (res) {
        console.log(res.errMsg)
      }
    })
  },

  //挂号凭证
  uploadImage(e) {

    var that = this
    wx.chooseImage({
      success(res) {
        const tempFilePaths = res.tempFilePaths
        console.log(tempFilePaths)
        const token = wx.getStorageSync('token')
        console.log(token)
        wx.uploadFile({
          // url: 'https://kpz.qixiaocheng.com/index.php?s=/api/upload/image&wxapp_id=' + App.getWxappId() + '&token=' + token,
          url: 'https://cpz2.qixiaocheng.com/index.php?s=/api/upload/image&wxapp_id=' + App.getWxappId() + '&token=' + token,
          filePath: tempFilePaths[0],
          name: 'iFile',
          formData: {
            'user': 'test'
          },
          success(res) {
            const data = JSON.parse(res.data)
            console.log(data, e.currentTarget.dataset.id)
            if (data.code == '-1') {
              that.doLogin(1)
            } else {
              if (e.currentTarget.dataset.id == '1') {
                that.setData({
                  register_image_url: data.data.file_path,
                  showImg: false
                })
                wx.setStorageSync('register_image_url', that.data.register_image_url)
              }else if (e.currentTarget.dataset.id == '6') {
                var drugs=that.data.drugs
                var index=e.currentTarget.dataset.index
                var objUrl={
                  url:data.data.file_path
                }
                drugs[index].key_image.push(objUrl)
                that.setData({
                  drugs: drugs,
                })
                wx.setStorageSync('drugs', that.data.drugs)
              } else {
                that.setData({
                  report_barcode_url: data.data.file_path,
                  showImg: false
                })
                wx.setStorageSync('report_barcode_url', that.data.report_barcode_url)
              }
            }
          }
        })
      }
    })
  },

  // 住院号
  bindHideInpatient_no(e) {
    this.setData({
      Inpatient_no: e.detail.value
    })
    wx.setStorageSync('Inpatient_no', this.data.Inpatient_no)
  },

  // 登记号
  bindHideregistration_no(e) {
    this.setData({
      registration_no: e.detail.value
    })
    wx.setStorageSync('registration_no', this.data.registration_no)
  },

  // 发票及身份证在何处
  bindHideInvoice_and_ID_card(e) {
    this.setData({
      Invoice_and_ID_card: e.detail.value
    })
    wx.setStorageSync('Invoice_and_ID_card', this.data.Invoice_and_ID_card)
  },
  // 内容概述
  bindHidesummary(e) {
    this.setData({
      summary: e.detail.value
    })
    wx.setStorageSync('summary', this.data.summary)
  },

  // 其他需求
  bindHideother_needs(e) {
    this.setData({
      other_needs: e.detail.value
    })
    wx.setStorageSync('other_needs', this.data.other_needs)
  },

  // 收件方式
  bindreceiving_method(e) {
    this.setData({
      receiving_method: e.detail.value
    })
    wx.setStorageSync('receiving_method', this.data.receiving_method)
  },

  // 联系电话
  bindHidephone(e) {
    this.setData({
      phone: e.detail.value
    })
    wx.setStorageSync('phone', this.data.phone)
  },
  // 病情介绍
  bindHidecase_presentation(e) {
    this.setData({
      case_presentation: e.detail.value
    })
    wx.setStorageSync('case_presentation', this.data.case_presentation)
  },

  // 添加药品
  addList() {
    let arr = this.data.drugs;
    let obj = {
      key_name: '',
      key_describe: '',
      key_image:[]
    }
    arr.push(obj)
    console.log(arr)
    this.setData({
      drugs: arr
    })

  },
  inputName: function (e) {
    let index = e.currentTarget.dataset.index //下标
    let drugs = this.data.drugs
    drugs[index].key_name = e.detail.value // 在第几项填写内容，就在数组中给对应项赋值
    this.setData({
      drugs: drugs
    })
    wx.setStorageSync('drugs', this.data.drugs)
  },

  inputkey_describe: function (e) {
    let index = e.currentTarget.dataset.index //下标
    let drugs = this.data.drugs
    drugs[index].key_describe = e.detail.value // 在第几项填写内容，就在数组中给对应项赋值
    this.setData({
      drugs: drugs
    })
    wx.setStorageSync('drugs', this.data.drugs)
  },
  remove: function(array, val) {
    for (var i = 0; i < array.length; i++) {
      if (array[i] == val) {
        array.splice(i, 1);
      }
    }
    return -1;
  },
  delDurg(e){
    var array = this.data.drugs;  //你的数组数据
    let index=e.currentTarget.dataset.index
    var val = this.data.drugs[index];  //你要移除的元素标识，例如下标之类的
    this.remove(array, val);   //调用方法传参
    this.setData({
      drugs: this.data.drugs
    })
  },

  onToAddress() {
    wx.navigateTo({
      url: '/pages/address/index?type=' + '1' + '&name=' + this.data.k_name + '&goods_id=' + this.data.goods_id + '&patient_id=' + this.data.patient_id + '&patient_name=' + this.data.patient_name + '&department_id=' + wx.getStorageSync('department_id_n') + '&mail_address_id=' + this.data.mail_address_id + '&address=' + this.data.address,
    })
  },
  bindHidecontent(e) {
    this.setData({
      service_content: e.detail.value
    })
    wx.setStorageSync('service_content', this.data.service_content)
  },


  onUnload(){
    wx.setStorageSync('call_phoneName','')
    wx.setStorageSync('buy_medicineName','')
    wx.setStorageSync('is_mailName','')
    wx.setStorageSync('is_ask','')
    wx.setStorageSync('report_type','')
    wx.setStorageSync('is_prescriptionName','')
    wx.setStorageSync('service_time','')
    wx.setStorageSync('discharge_time','')
    wx.setStorageSync('register_image_url', '')
    wx.setStorageSync('report_barcode_url', '')
    wx.setStorageSync('receiving_method', '')
    wx.setStorageSync('case_presentation', '')
    wx.setStorageSync('phone','')
    wx.setStorageSync('service_content', '')
    wx.setStorageSync('other_needs', '')
    wx.setStorageSync('Inpatient_no', '')
    wx.setStorageSync('registration_no', '')
    wx.setStorageSync('Invoice_and_ID_card', '')
    wx.setStorageSync('summary', '')
    wx.setStorageSync('patient_id','')
    wx.setStorageSync('patient_name','')
    var duag= [{
      key_name: '',
      key_describe: '',
      key_image:[]
    }]
    wx.setStorageSync('drugs', duag)
    this.setData({
      checkeds:false
    })
    // wx.navigateBack()
  }
})